Skip to content

fix(sdk-api): require previous transactions for v1 non-segwit psbt inputs - #10190

Open
prikshitchawla300 wants to merge 2 commits into
masterfrom
prikshitchawla/cshld-2230-v1-psbt-require-prev-tx
Open

prikshitchawla300 wants to merge 2 commits into
masterfrom
prikshitchawla/cshld-2230-v1-psbt-require-prev-tx

Conversation

@prikshitchawla300

@prikshitchawla300 prikshitchawla300 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The legacy sighash used by non-segwit (p2sh) inputs does not commit to the input value, so the full previous transaction (nonWitnessUtxo) is needed to know what an input spends. The v1 PSBT path built and signed p2sh inputs from witnessUtxo only (skipNonWitnessUtxo + withUnsafeNonSegwit). This change makes it require and verify the previous transaction.

Behaviour change

  • Signer (signPsbtRequest): refuses the whole PSBT if any p2sh input has no nonWitnessUtxo, or its nonWitnessUtxo does not hash to the txid the input spends. Signing now runs in safe mode (withUnsafeNonSegwit(..., false)). Segwit and taproot inputs are unchanged.
  • Builder (createTransaction with usePsbt): attaches the previous transaction of every p2sh input instead of using skipNonWitnessUtxo. It is taken from the unspent's prevTx if present, otherwise fetched from BitGo's v1 tx endpoint (GET /api/v1/tx/:txid). The v1 indexer returns the transaction without witness data, which is enough for nonWitnessUtxo since it is only checked against the txid. It must match the input's txid, and the spent output must have the unspent's script and value.
  • Fallback: if a previous transaction contradicts the unspent data (PrevTxMismatchError), createTransaction rejects instead of falling back to the legacy format. Other PSBT build errors, including a failed fetch or a response without a hex, still fall back as before.

BREAKING CHANGE: v1 signTransaction no longer signs PSBTs whose p2sh inputs only carry witnessUtxo. PSBTs built by this SDK now include the previous transactions. PSBTs built elsewhere must include nonWitnessUtxo for p2sh inputs.

Changes

  • modules/sdk-api/src/v1/signPsbt.ts: nonWitnessUtxo check, safe-mode signing
  • modules/sdk-api/src/v1/transactionBuilder.ts: fetch and verify previous transactions, PrevTxMismatchError
  • modules/sdk-api/src/v1/wallet.ts: no legacy fallback on PrevTxMismatchError
  • Tests in test/unit/v1/signPsbt.ts and test/unit/v1/wallet.ts

Testing

  • sdk-api unit tests: 297 passing
  • New tests cover: p2sh input without nonWitnessUtxo refused, one bad input refuses the whole PSBT, nonWitnessUtxo of another transaction refused, segwit inputs still sign from witnessUtxo, fetch from /api/v1/tx/:txid, value / txid / script mismatch rejected without fallback, and a failed fetch or missing hex still falling back.
  • Coverage check on test (read-only script, all 14 v1 wallets visible to the test account): 266 unspents (261 p2sh). For every one, /api/v1/tx/:txid returned a hex that hashes to the txid and has the expected output value and script.
  • 8 of the new tests fail on the previous code.

Ticket: CSHLD-2230

@prikshitchawla300
prikshitchawla300 requested a review from a team as a code owner November 17, 2026 10:32

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@linear-code

linear-code Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

CSHLD-2230

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Compatibility checks are failing on Node.js 27-nightly (experimental, non-blocking). This does not block merge, but it signals an incompatibility to fix before this release becomes supported.

View run

@prikshitchawla300
prikshitchawla300 force-pushed the prikshitchawla/cshld-2230-v1-psbt-require-prev-tx branch from fa6f89c to 4e6d9d9 Compare November 24, 2026 10:54
@veetragjain

Copy link
Copy Markdown
Contributor

The txid is not validated before it goes into the URL.

…puts

The legacy sighash used by non-segwit (p2sh) inputs does not commit to
the input value, so the full previous transaction is needed to know
what an input spends.

- signPsbtRequest refuses a PSBT if any p2sh input lacks
  nonWitnessUtxo or its nonWitnessUtxo does not hash to the txid the
  input spends, and signs in safe mode instead of withUnsafeNonSegwit.
- The v1 PSBT builder attaches the previous transaction of every p2sh
  input instead of using skipNonWitnessUtxo. It is taken from the
  unspent's prevTx or fetched from the BitGo v1 tx endpoint
  (GET /api/v1/tx/:txid), and must match the input's txid, script and
  value.
- createTransaction no longer falls back to the legacy format when a
  previous transaction contradicts the unspent data
  (PrevTxMismatchError). Other PSBT build errors still fall back.

BREAKING CHANGE: v1 signTransaction no longer signs PSBTs whose p2sh
inputs only carry witnessUtxo. PSBTs built by this SDK now include the
previous transactions; PSBTs built elsewhere must include
nonWitnessUtxo for p2sh inputs.

Ticket: CSHLD-2230
@prikshitchawla300
prikshitchawla300 force-pushed the prikshitchawla/cshld-2230-v1-psbt-require-prev-tx branch from 4e6d9d9 to de63b52 Compare November 24, 2026 13:54
@prikshitchawla300
prikshitchawla300 force-pushed the prikshitchawla/cshld-2230-v1-psbt-require-prev-tx branch from e2ad6f2 to 82a4baf Compare November 25, 2026 09:37

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants